package cn.iocoder.yudao.module.of.controller.admin.meetingminutesenduser;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.of.controller.admin.meetingminutesenduser.vo.*;
import cn.iocoder.yudao.module.of.dal.dataobject.meetingminutesenduser.MeetingMinuteSendUserDO;
import cn.iocoder.yudao.module.of.service.meetingminutesenduser.MeetingMinuteSendUserService;

@Tag(name = "管理后台 - 会议纪要下派人员")
@RestController
@RequestMapping("/of/meeting-minute-send-user")
@Validated
public class MeetingMinuteSendUserController {

    @Resource
    private MeetingMinuteSendUserService meetingMinuteSendUserService;

    @PostMapping("/create")
    @Operation(summary = "创建会议纪要下派人员")
    @PreAuthorize("@ss.hasPermission('of:meeting-minute-send-user:create')")
    public CommonResult<Long> createMeetingMinuteSendUser(@Valid @RequestBody MeetingMinuteSendUserSaveReqVO createReqVO) {
        return success(meetingMinuteSendUserService.createMeetingMinuteSendUser(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新会议纪要下派人员")
    @PreAuthorize("@ss.hasPermission('of:meeting-minute-send-user:update')")
    public CommonResult<Boolean> updateMeetingMinuteSendUser(@Valid @RequestBody MeetingMinuteSendUserSaveReqVO updateReqVO) {
        meetingMinuteSendUserService.updateMeetingMinuteSendUser(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除会议纪要下派人员")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('of:meeting-minute-send-user:delete')")
    public CommonResult<Boolean> deleteMeetingMinuteSendUser(@RequestParam("id") Long id) {
        meetingMinuteSendUserService.deleteMeetingMinuteSendUser(id);
        return success(true);
    }



    @GetMapping("/get")
    @Operation(summary = "获得会议纪要下派人员")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('of:meeting-minute-send-user:query')")
    public CommonResult<MeetingMinuteSendUserRespVO> getMeetingMinuteSendUser(@RequestParam("id") Long id) {
        MeetingMinuteSendUserDO meetingMinuteSendUser = meetingMinuteSendUserService.getMeetingMinuteSendUser(id);
        return success(BeanUtils.toBean(meetingMinuteSendUser, MeetingMinuteSendUserRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得会议纪要下派人员分页")
    @PreAuthorize("@ss.hasPermission('of:meeting-minute-send-user:query')")
    public CommonResult<PageResult<MeetingMinuteSendUserRespVO>> getMeetingMinuteSendUserPage(@Valid MeetingMinuteSendUserPageReqVO pageReqVO) {
        PageResult<MeetingMinuteSendUserDO> pageResult = meetingMinuteSendUserService.getMeetingMinuteSendUserPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MeetingMinuteSendUserRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出会议纪要下派人员 Excel")
    @PreAuthorize("@ss.hasPermission('of:meeting-minute-send-user:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportMeetingMinuteSendUserExcel(@Valid MeetingMinuteSendUserPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<MeetingMinuteSendUserDO> list = meetingMinuteSendUserService.getMeetingMinuteSendUserPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "会议纪要下派人员.xls", "数据", MeetingMinuteSendUserRespVO.class,
                        BeanUtils.toBean(list, MeetingMinuteSendUserRespVO.class));
    }

}